#!/usr/bin/env python2.5

class A (object):
    derived_types = set()
    def __new__ (cls):
        if not cls in A.derived_types:
            A.derived_types.add(cls)
            cls.all_nodes = list()
            cls.a_index   = [0]
            print "add to %s " % cls.__name__
        new_A = super(A, cls).__new__(cls)
        new_A.all_nodes = cls.all_nodes
        new_A.a_index   = cls.a_index
        cls.a_index[0] +=1
        cls.all_nodes.append(new_A)
        return new_A

    def __init__ (self):
        self.index = self.a_index[0]
        pass

    def __str__ (self):
        return str(self.index)

class B(A):
    pass

